import {
    editBtnHandler
} from './edit';
import {
    grid
} from '../common/grid';
import {
    editPwd,
    loginOut
} from '../common/settings';


$(function () {
    grid();
    window.editPwd = editPwd;
    window.loginOut = loginOut;


    let $table = $('#table').bootstrapTable({
        toolbar: '#toolbar',
        url: GLOBAL_listUrl,
        sidePagination: "server",

        sortName: 'config',
        columns: [{
            radio: true
        }, {
            field: 'config_name',
            title: '配置名称',
            sortable: true
        },{
            field: 'config',
            title: '配置参数',
            sortable: true
        }, {
            field: 'val',
            title: '值',
            sortable: true
        }]
    });

    //多选不能编辑
    $table.on('check.bs.table', () => {
        let selectedList = $('#table').bootstrapTable('getSelections');
        if (selectedList.length > 1) {
            $('#editBtn').attr('disabled', 'disabled');
            return;
        }
        $('#editBtn').removeAttr('disabled');
    });
    $table.on('uncheck.bs.table', () => {
        let selectedList = $('#table').bootstrapTable('getSelections');
        if (selectedList.length > 1) {
            $('#editBtn').attr('disabled', 'disabled');
            return;
        }
        $('#editBtn').removeAttr('disabled');
    });
    $table.on('check-all.bs.table', (rows) => {
        $('#editBtn').attr('disabled', 'disabled');
    });
    $table.on('uncheck-all.bs.table', (rows) => {
        $('#editBtn').removeAttr('disabled');
    });

    window.editBtnHandler = editBtnHandler;


});

